var layerFlag=T.p("layerFlag");
var jobId = T.p("jobId");
if(layerFlag=="undefined"||layerFlag==null){
    layerFlag = false;
}else{
	layerFlag =true;
}
$(function () {
    $("#jqGrid").jqGrid({
        url: '../workSubject/list',
        datatype: "json",
        postData:{jobId:jobId},
        colModel: [
			{ label: 'id', name: 'id', width: 50, key: true },
			{ label: '主题专题名称', name: 'subjectName', width: 80 },
			{ label: '描述', name: 'remark', width: 80 },
			{ label: '创建时间', name: 'createTime', width: 80 },
			{ label: '更新时间', name: 'updateTime', width: 80 }
        ],
		viewrecords: true,
        height: 800,
        rowNum: 20,
		rowList : [20,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
			root: "page.data",
			page: "page.pageNo",
			total: "page.pageCount",
			records: "page.count"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	//$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
        isShowCond:true,
        btnText:'隐藏',
        qryForm:{
            subjectName:''
        }
	},
	methods: {
        reset: function(){
        	this.qryForm.subjectName='';
        },
        query: function () {
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{subjectNameLike:'%'+vm.qryForm.subjectName+'%'
                },
                page:1
            }).trigger("reloadGrid");
        },
        toggle:function(){
            this.isShowCond = !this.isShowCond;

            if(this.isShowCond==true){
                this.btnText = "隐藏"
            }else if(this.isShowCond==false){
                this.btnText = "查询"
            }

        },
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			
			location.href = "workSubject_add.html?id="+id;
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../workSubject/delete",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
        runOnce: function (event) {
            var ids = getSelectedRows();
            if(ids == null){
                return ;
            }

            confirm('确定要立即执行选中的记录？', function(){
                $.ajax({
                    type: "POST",
                    url: "../workSubject/run",
                    data: JSON.stringify(ids),
                    success: function(r){
                        if(r.code == 0){
                            alert('操作成功', function(index){
                                $("#jqGrid").trigger("reloadGrid");
                            });
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            });
        }
	}
});
